//
//  RenWuXiangQingViewController.m
//  firstpoint
//
//  Created by 泽中 on 2017/6/28.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "RenWuXiangQingViewController.h"
#import "LeeRenWuXXCYViewController.h"//参与
@interface RenWuXiangQingViewController ()
{
    UILabel*titleLab;//标题
    //内容
    UILabel*infoLab;
    //金豆
    UILabel*jindouLab;
    //活动时间
    UILabel*huodongTimeLab;
    //参与人数
    UILabel*canyurenshuLab;
    //
    UILabel *xiangqingLbale;
}
@end

@implementation RenWuXiangQingViewController
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden=NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"任务详情";
    self.view.backgroundColor=LRRGBColor(230, 240, 243);
    [self setUI];
    [self setUItwo];
    [self navButton];
    [self httpRuqestRenWuXiangQing];//详情
}
-(void)navButton
{
    UIButton* rightBun = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBun.frame = CGRectMake(0, 0, 20, 20);
    [rightBun setBackgroundImage:[UIImage imageNamed:@"rwlc"] forState:normal];
    [rightBun addTarget:self action:@selector(fenxiangbtnClcike) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* right = [[UIBarButtonItem alloc] initWithCustomView:rightBun];
//    self.navigationItem.rightBarButtonItem = right;
    
    
    
    UIButton* rightBtntwo = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtntwo.frame = CGRectMake(40, 0, 20, 20);
    [rightBtntwo setBackgroundImage:[UIImage imageNamed:@"rwsc"] forState:normal];
    [rightBtntwo addTarget:self action:@selector(shouchangBtnClcike) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* righttwo = [[UIBarButtonItem alloc] initWithCustomView:rightBtntwo];
//    self.navigationItem.rightBarButtonItem = righttwo;
    
    
    self.navigationItem.rightBarButtonItems  = @[right,righttwo];
}
-(void)setUI
{
    //报名按钮
    UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, height_screen-50, width_screen, 50);
    button.backgroundColor=[UIColor orangeColor];
    [button setTitle:@"立即报名" forState:0];
    [button setTitleColor:[UIColor whiteColor] forState:0];
    [button addTarget:self action:@selector(lijibaomingBtnClcike) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, width_screen, 78)];
    view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view];
    UIImageView*imgView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 15, 15)];
    imgView.backgroundColor=[UIColor orangeColor];
    [view addSubview:imgView];
    //标题
    titleLab=[[UILabel alloc]initWithFrame:CGRectMake(30, 10, width_screen-40, 15)];
    titleLab.font=[UIFont systemFontOfSize:15];
//    titleLab.text=@"唱片店内 传来异国民谣";
    [view addSubview:titleLab];
    //内容
    infoLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 35, width_screen-20, 33)];
    infoLab.numberOfLines=0;
//    infoLab.text=@"原来过得很快乐 只我一人未发觉 如能忘掉渴望 岁月长 衣裳薄";
    infoLab.font=[UIFont systemFontOfSize:13];
    infoLab.textColor=LRRGBColor(163, 164, 165);
    [view addSubview:infoLab];
}

-(void)setUItwo
{
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 152, width_screen, height_screen-152-170)];
    view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view];
    
    UIView*fengeView=[[UIView alloc]initWithFrame:CGRectMake(10, 60, width_screen-20, 1)];
    fengeView.backgroundColor=LRRGBColor(230, 240, 243);
    [view addSubview:fengeView];
    //金豆
    jindouLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 19, width_screen/2, 22)];
    jindouLab.textColor=[UIColor orangeColor];
//    jindouLab.text=@"182 金豆";
    jindouLab.font=[UIFont systemFontOfSize:22];
    [view addSubview:jindouLab];
    //活动时间
    huodongTimeLab=[[UILabel alloc]initWithFrame:CGRectMake(width_screen-130, 19, 120, 10)];
    huodongTimeLab.font=[UIFont systemFontOfSize:10];
//    huodongTimeLab.text=@"活动时间 2012-10-9";
    huodongTimeLab.textColor=LRRGBColor(163, 164, 165);

    [view addSubview:huodongTimeLab];
    //参与人数
    canyurenshuLab=[[UILabel alloc]initWithFrame:CGRectMake(width_screen-130, 34, 120, 10)];
    canyurenshuLab.font=[UIFont systemFontOfSize:10];
    canyurenshuLab.textColor=LRRGBColor(163, 164, 165);

//    canyurenshuLab.text=@"参与人数 1111";
    [view addSubview:canyurenshuLab];
    //任务详情
    UILabel *renwuxiangq = [[UILabel alloc]initWithFrame:CGRectMake(15, 75, 200, 20)];
    renwuxiangq.font=[UIFont systemFontOfSize:20];
    renwuxiangq.text = @"任务详情";
    renwuxiangq.textColor=LRRGBColor(0, 119, 190);
    [view addSubview: renwuxiangq];
    
    
    NSArray *arrti = @[@"名称:",@"时间:",@"任务目标:",@"任务人数:",@"其他:",@"工作日期:",@"工作时段:",@"性别:",@"年龄:",@"任务区域:"];
    for (int i=0; i<10; i++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 120+(20*i), 70, 20)];
        label.text = arrti[i];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = LRRGBColor(163, 164, 165);
        [view addSubview:label];
        
    }
    for (int i=0; i<10; i++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(75, 120+(20*i), width_screen-100, 20)];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = LRRGBColor(163, 164, 165);
        label.tag = 100+i;
        [view addSubview:label];
        
    }
    
    
    
}
#pragma mark---收藏按钮点击事件
//收藏
-(void)shouchangBtnClcike{
    [HTTPURL postRequest:LINK_BASE_URL(@"favorites/saveFavorites.api") parameters:@{@"sourceId":_idString,@"sourceType":@"1",@"userId":userid} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"data"]intValue]==1) {
            UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"收藏任务成功" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
            [alertview show];
        }else{
            NSString *str = responseObject[@"retInfo"];
            UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
            [alertview show];
        }
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
//分享
-(void)fenxiangbtnClcike{
    
}
//立即报名
-(void)lijibaomingBtnClcike{
    
    
    
    __weak typeof(self) waekSelf = self;
    [waekSelf.navigationController pushViewController:[LeeRenWuXXCYViewController new] animated:YES];
    NSInteger taskId = [_idString integerValue];
    NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"task/joinTask.api?access_token="),NSUD_Obj(@"token")];
    [HTTPURL postRequest:url parameters:@{@"taskId":@(taskId)} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        NSLog(@"%@",responseObject[@"data"]);
        if ([responseObject[@"data"]intValue]==1) {
            [waekSelf promptViewmessage:@"报名成功是否现在去完成" sureBlock:^{
                NSLog(@"11111");
            } suerb:^{
                NSLog(@"22222");
            }];
        }else{
            NSString *str = responseObject[@"retInfo"];
            UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
            [alertview show];
        }
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
#pragma mark---任务详情
-(void)httpRuqestRenWuXiangQing{
    NSLog(@"%@",_idString);
    __weak typeof(self) waekSelf = self;
    NSInteger taskId = [_idString integerValue];
    NSString *url = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"task/chackTaskInfo.api?access_token="),NSUD_Obj(@"token")];
    [HTTPURL postRequest:url parameters:@{@"taskId":@(taskId)} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"retFlag"]integerValue]==1) {
            NSDictionary *dic = [PublicTools dictionaryWithJsonString:responseObject[@"data"]];
            [waekSelf xiugaixianshi:dic];
        }
        
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}
-(void)xiugaixianshi:(NSDictionary *)dic{
    titleLab.text = [NSString stringWithFormat:@"%@",dic[@"title"]];
    //内容
    infoLab.text = [NSString stringWithFormat:@"%@",dic[@"description"]];
    //金豆
    jindouLab.text = [NSString stringWithFormat:@"%@ 金豆",dic[@"payTypeId"]];
    //活动时间
    NSArray *arr = [dic[@"releaseTime"] componentsSeparatedByString:@" "];
    NSArray *endArr = [dic[@"endTime"] componentsSeparatedByString:@" "];//结束时间
    NSLog(@"%@",arr[0]);
    huodongTimeLab.text = [NSString stringWithFormat:@"活动时间 %@-%@",arr[0],@"2017-12-12"];
    //参与人数
    canyurenshuLab.text = [NSString stringWithFormat:@"参与人数 %@",dic[@"counts"]];
    
    UILabel *label1 = [self.view viewWithTag:100];
    label1.text = [NSString stringWithFormat:@"%@",dic[@"Title"]];//名称
    UILabel *label2 = [self.view viewWithTag:101];
    label2.text = [NSString stringWithFormat:@"活动时间 %@-%@",arr[0],@"2017-12-12"];;//时间
    UILabel *label3 = [self.view viewWithTag:102];
    label3.text = [NSString stringWithFormat:@"%@",dic[@""]];//任务目标
    UILabel *label4 = [self.view viewWithTag:103];
    label4.text = [NSString stringWithFormat:@"%@",dic[@"peopleCount"]];//任务人数
    UILabel *label5 = [self.view viewWithTag:104];
    label5.text = [NSString stringWithFormat:@"%@",dic[@""]];//其他
    UILabel *label6 = [self.view viewWithTag:105];
    label6.text = [NSString stringWithFormat:@"%@",dic[@"workingDate"]];//工作日期
    UILabel *label7 = [self.view viewWithTag:106];
    label7.text = [NSString stringWithFormat:@"%@",dic[@""]];//工作时段
    UILabel *label8 = [self.view viewWithTag:107];
    label8.text = [NSString stringWithFormat:@"%@",dic[@"sex"]];//性别
    UILabel *label9 = [self.view viewWithTag:108];
    label9.text = [NSString stringWithFormat:@"%@",dic[@"endAge"]];//年龄
    UILabel *label10 = [self.view viewWithTag:109];
    label10.text = [NSString stringWithFormat:@"%@",dic[@"areaId"]];//任务区域

    
}
-(void)promptViewmessage:(NSString *)message sureBlock:(void(^)())sureBlock suerb:(void(^)())tsureBlock{
    UIAlertController * alert=[UICommonView showTwoAlertWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert sureTitle:@"取消" cancelTitle:@"去完成" sureBlock:^{
        
    } cancelBlock:^{
        
    }];
    [self presentViewController:alert animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
